<?php

/**
 * 文件由尚数增量代码引擎生成
 * @author: Shann 851188611@qq.com
 */

namespace app\admin\controller;

class FileBase
{
    public function index()
    {
        $file_query = \app\model\File::field(['id', 'name', 'type_value', 'url', 'hash', 'created_at']);

        $file_model = $file_query->select();

        return json(['code' => 20000, 'data' => ['files' => $file_model]]);
    }

    public function detail()
    {
        $file_query = \app\model\File::field(['id', 'name', 'type_value', 'url', 'hash', 'created_at']);

        $file_query->where('id', input('id'));

        $file_model = $file_query->find();

        return json(['code' => 20000, 'data' => ['file' => $file_model]]);
    }

    public function create()
    {
        $param = request()->param(['name', 'typeValue', 'url', 'hash']);

        $model = new \app\model\File();

        $model->save($param);

        $model = \app\model\File::find($model->id);

        return json(['code' => 20000, 'msg' => 'success', 'data' => ['file' => $model]]);
    }

    public function delete()
    {
        \app\model\File::destroy(function ($query) {
            $query->where('id', input('id'));
        });

        return json(['code' => 20000, 'msg' => 'success']);
    }
}
